import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:getx_scaffold/getx_scaffold.dart';
import 'package:oramemo/common/langs/index.dart';
import 'package:oramemo/common/routes/routes.dart';
import 'package:oramemo/common/styles/theme.dart';
import 'package:oramemo/core/controllers/version_controller.dart';
import 'package:oramemo/core/services/storage_service.dart';
import 'package:oramemo/pages/home/home_view.dart';

import 'core/controllers/auth_controller.dart';
import 'pages/login/page/login_page.dart';
import 'pages/login/page/sms_login_page.dart';

/**
 * @author: Kxmrg
 * @github: https://github.com/Kxmrg
 * @version: 1.0.0
 * @copyright: Copyright © 2023-2024 Kxmrg
 * @license: MIT License
 * @date: 2024-07-03
 * @description:
 */

/// Main
void main() async {
  WidgetsBinding widgetsBinding = await init(
    isDebug: kDebugMode,
    logTag: 'GetxScaffold',
    supportedLocales: TranslationLibrary.supportedLocales,
  );
  //FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
  SystemUiOverlayStyle systemUiOverlayStyle =
      const SystemUiOverlayStyle(statusBarColor: Colors.transparent);
  SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);

  await Get.putAsync(() => StorageService().init());
  String? token = StorageService.to.getToken();
  final bool = token?.isNotEmpty == true;
  runApp(
    GetxApp(
      // 设计稿尺寸 单位：dp
      designSize: const Size(393, 852),
      // Getx Log
      enableLog: kDebugMode,
      // 默认的跳转动画
      defaultTransition: Transition.fadeIn,
      // 主题模式
      themeMode: GlobalService.to.themeMode,
      // 主题
      theme: AppTheme.light,
      // Dark主题
      darkTheme: AppTheme.dark,
      // 国际化配置
      locale: GlobalService.to.locale,
      translations: TranslationLibrary(),
      fallbackLocale: TranslationLibrary.fallbackLocale,
      supportedLocales: TranslationLibrary.supportedLocales,
      localizationsDelegates: TranslationLibrary.localizationsDelegates,
      // AppTitle
      title: 'OraMemo',
      getPages: Routers.routes,
      // 首页
      home: bool ? const HomePage() : const SMSLoginPage(),
      onInit: () {
        _init();
      },
      // Builder
      builder: (context, widget) {
        // do something....
        return widget!;
      },
    ),
  );
}

void _init() async {
  Get.put(AuthController());
  Get.put(VersionController());
}
